package com.cfilmcloud.learn.demo;

import com.cfilmcloud.learn.domain.Learn;
import org.assertj.core.util.Lists;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

/**
 * Created by edz on 2017/7/13.
 */
public class DemoStream {

    public static void main(String[] args) {
        //生成器
        final Supplier<Learn> learnSupplier = Learn::new;

        //mock
        final Function<String, Learn> mockLearn = (x) -> {
            Learn learn = learnSupplier.get();
            learn.setId("id_" + x);
            learn.setName("name_" + x);
            learn.setQuestion("question_" + x);
            return learn;
        };
        String aa = "";

        final List<Learn> learns = Lists.newArrayList(mockLearn.apply("4"), mockLearn.apply("2"), mockLearn.apply("3"));

        learns.stream().sorted(Comparator.comparing(learn -> learn.getId())).map(learn -> {
            String ss = "";
            return learn.getId() + " -- " + learn.getName() + " -- " + learn.getQuestion();
        }).forEach(s -> System.err.println(s));

        System.err.println("**********************************************************************************");

        String aaa = learns.parallelStream().map(learn -> {
            return learn.getId() + " -- " + learn.getName() + " -- " + learn.getQuestion();
        }).findFirst().get();

        String ssss = "";

        for (Learn learnaa : learns){
            ssss = "" ;
        }


    }
}
